﻿Public Class Cetatenie
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        TextBoxMisID.Text = ReturnMisiuneID()

    End Sub

    Protected Sub Button_Cautare_Click(sender As Object, e As EventArgs) Handles Button_Cautare.Click

        GridView1.Visible = False
        TextBoxNume.Visible = False
        TextBoxPrenume.Visible = False        
        DetailsView3.Visible = False


        DetailsView2.DataBind()
        If IsNothing(DetailsView2.SelectedValue) = False Then
            TextBoxSearch.Text = DetailsView2.Rows(3).Cells(1).Text
            TextBoxSearch.DataBind()
            TextBoxServID.Text = DetailsView2.Rows(6).Cells(1).Text
            TextBoxServID.DataBind()
        End If
        TextBoxSearch.DataBind()
        DetailsView1.DataBind()
        TextBoxServID.DataBind()
    End Sub

    Protected Sub Button_CautareANC_Click(sender As Object, e As EventArgs) Handles Button_CautareANC.Click
        TextBoxNume.Visible = True
        TextBoxPrenume.Visible = True
        numeprenumeLabel.Text = TextBoxNume.Text & " " & TextBoxPrenume.Text
        If DetailsView3.Visible = False Then
            TextBoxNume.Text = DetailsView1.Rows(2).Cells(1).Text.Trim()
            TextBoxPrenume.Text = DetailsView1.Rows(3).Cells(1).Text.Trim()
            DetailsView3.Visible = True
        End If
        DetailsView3.DataBind()
        GridView1.Visible = False
    End Sub

    

    Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)

    End Sub

    Protected Sub DetailsView1_DataBound(sender As Object, e As EventArgs) Handles DetailsView1.DataBound
        If DetailsView1.CurrentMode = DetailsViewMode.Edit Then
            DetailsView1.ChangeMode(DetailsViewMode.ReadOnly)
        End If
        If IsNothing(DetailsView2.SelectedValue) = False Then
            If DetailsView2.Rows(1).Cells(1).Text.Trim() = ReturnMisiuneID().ToString Then
                DetailsView1.Enabled = True
                If DetailsView2.Rows(2).Cells(1).Text.Length = 6 Or DetailsView2.Rows(2).Cells(1).Text.Length = 0 Then
                    DetailsView1.Enabled = True
                Else
                    DetailsView1.Enabled = False
                End If
            Else
                DetailsView1.Enabled = False
            End If
        End If
    End Sub
    
    Protected Sub DetailsView2_DataBound(sender As Object, e As EventArgs) Handles DetailsView2.DataBound
        If DetailsView2.CurrentMode = DetailsViewMode.Edit Then
            DetailsView2.ChangeMode(DetailsViewMode.ReadOnly)
        End If
        If IsNothing(DetailsView2.SelectedValue) = False Then
            If DetailsView2.Rows(1).Cells(1).Text.Trim() = ReturnMisiuneID().ToString Then
                DetailsView2.Enabled = True
                If DetailsView2.Rows(2).Cells(1).Text.Length = 6 Or DetailsView2.Rows(2).Cells(1).Text.Length = 0 Then
                    DetailsView2.Enabled = True
                Else
                    DetailsView2.Enabled = False
                End If
            Else
                DetailsView2.Enabled = False
            End If


            If DetailsView2.Rows(6).Cells(1).Text.Trim() = 1 Then
                Label9.Visible = True
                DropDownListCopiiM.Visible = True
            Else
                Label9.Visible = False
                DropDownListCopiiM.Visible = False
            End If
        End If
    End Sub

    Protected Sub DetailsView2_ItemDeleting(ByVal sender As Object, ByVal e As DetailsViewDeleteEventArgs)

        If IsNothing(DropDownListSubserv.SelectedValue) = True Then
            'MsgBox("Selectati subserviciul!", MsgBoxStyle.Exclamation, Title:="Cetătenie")
            LabelMSG.Text = "Selectați subserviciul!"
            LabelMSG.Visible = True
            e.Cancel = True
        Else
            If IsNothing(DropDownListTAXA.SelectedValue) = True Then
                'MsgBox("Selectati taxa consulară!", MsgBoxStyle.Exclamation, Title:="Cetătenie")
                LabelMSG.Text = "Selectați taxa consulară!"
                LabelMSG.Visible = True
                e.Cancel = True
            Else
                If DetailsView2.Rows(2).Cells(1).Text.Length = 6 Or DetailsView1.Rows(2).Cells(1).Text.Length = 0 Then
                    'Select Case MsgBox("Dosarul va fi preluat! Confirmați?", MsgBoxStyle.YesNo, Title = "Cetătenie")
                    ' Case MsgBoxResult.No
                    ' e.Cancel = True
                    ' End Select
                Else
                    e.Cancel = True
                End If
            End If
        End If
    End Sub

    Public Function ReturnMisiuneID() As Integer

        Dim misIDadapter As New eServicii.DataSetJURAMANTTableAdapters.aspnet_UsersTableAdapter
        Dim MisiuneID As Integer
        Dim NumeUser As String
        If HttpContext.Current.Request.IsAuthenticated Then
            NumeUser = Membership.GetUser().UserName()
            NumeUser = HttpContext.Current.User.Identity.Name
            MisiuneID = misIDadapter.GetDataMisID(NumeUser).Rows(0).Item("MisiuneID")
            Return MisiuneID
        Else
            Return 0
        End If
    End Function

    Protected Sub TextBoxServID_TextChanged(sender As Object, e As EventArgs) Handles TextBoxServID.TextChanged
        
    End Sub

    Protected Sub DropDownListSubserv_SelectedIndexChanged(sender As Object, e As EventArgs)
        LabelMSG.Visible = False
    End Sub

    Protected Sub DropDownListCopiiM_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownListCopiiM.SelectedIndexChanged
        
    End Sub

    Protected Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        TextBoxNume.Visible = True
        TextBoxPrenume.Visible = True        
        If GridView1.Visible = False Then
            TextBoxNume.Text = DetailsView1.Rows(2).Cells(1).Text.Trim()
            TextBoxPrenume.Text = DetailsView1.Rows(3).Cells(1).Text.Trim()
            GridView1.Visible = True
        End If
        GridView1.DataBind()
        DetailsView3.Visible = False
    End Sub

    Protected Sub TextBoxNume_TextChanged(sender As Object, e As EventArgs) Handles TextBoxNume.TextChanged

    End Sub

    Protected Sub DropDownListTAXA_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownListTAXA.SelectedIndexChanged
        LabelMSG.Visible = False
    End Sub
End Class